﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>运单信息</title>
    <!--<link href="../../script/css/bootstrap.css" rel="stylesheet" />
    <link href="../../script/css/bootstrap-theme.css" rel="stylesheet" />
    <link href="../../script/css/select2.css" rel="stylesheet" />
    <link href="../../script/css/bootstrap-datetimepicker.css" rel="stylesheet" />
    <script src="../../script/js/jquery-1.12.3.js"></script>
    <script src="../../script/js/bootstrap.js"></script>
    <script src="../../script/js/select2.full.js"></script>
    <script src="../../script/js/bootstrap-datetimepicker.js"></script>
    <script src="../../script/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../../script/js/cus-edit.js"></script>
    <script src="../../script/js/cus-dirs.js"></script>
    <script src="../../script/js/common.js"></script>-->
</head>
<body>
    <style>
        .row {
            margin-top: 1em;
        }
    </style>
    <div>
        <form>
            <div>
                <div class="panel-group" id="accordion">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapse0">
                                    路线选择
                                </a>
                            </h4>
                        </div>
                        <div id="collapse0" class="panel-collapse collapse in">
                            <div class="panel-body">
                                <div class='row'>
                                    <div class='col-md-6'>
                                        <label>目的地</label>
                                        <select class='form-control' name='earea' data-type='select'></select>
                                    </div>
                                    <div class='col-md-6'>
                                        <label>发货地</label>
                                        <select class='form-control' name='barea' data-type='select'></select>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class='col-md-6'>
                                        <a class="btn btn-default" href="#" onclick="next(this);">下一步</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
                                    提货人信息
                                </a>
                            </h4>
                        </div>
                        <div id="collapse1" class="panel-collapse collapse in">
                            <div class="panel-body">
                                <div class='row'>
                                    <div class='col-md-6'>
                                        <label>提货人</label>
                                        <input class='form-control' name='thname' data-type='text' />
                                    </div>
                                    <div class='col-md-6'>
                                        <label>提货人手机</label>
                                        <input class='form-control' name='thphone' data-type='text' />
                                    </div>
                                </div>
                                <div class='row'>
                                    <div class='col-md-6'>
                                        <label>重量（吨）</label>
                                        <input class='form-control' name='weight' data-type='text' />
                                    </div>
                                    <div class='col-md-6'>
                                        <label>体积（方）</label>
                                        <input class='form-control' name='volume' data-type='text' />
                                    </div>
                                </div>
                                <div class='row'>
                                    <div class='col-md-6'>
                                        <label>货物总价</label>
                                        <input class='form-control' name='tolvalue' data-type='text' />
                                    </div>
                                </div>
                                <div class='row'>
                                    <div class='col-md-12'>
                                        <label>说明</label>
                                        <textarea class='form-control' name='remark' data-type='text'></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class='col-md-6'>
                                        <a class="btn btn-default" href="#" onclick="next(this);">下一步</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
                                    选择承运商
                                </a>
                            </h4>
                        </div>
                        <div id="collapse2" class="panel-collapse collapse in">
                            <div class="panel-body">
                                <div class="row">
                                    <div class='col-md-6'>
                                        <label>承运方</label>
                                        <select class='form-control' name='company2' data-type='select'></select>
                                    </div>
                                    <div class='col-md-6'>
                                        <label>发货方</label>
                                        <select class='form-control' name='company1' data-type='select'></select>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class='col-md-6'>
                                        <a class="btn btn-default" href="#" onclick="next(this);">下一步</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapse3">
                                    费用信息
                                </a>
                            </h4>
                        </div>
                        <div id="collapse3" class="panel-collapse collapse in">
                            <div class="panel-body">
                                <div class='row'>

                                    <div class='col-md-6'>
                                        <label>运费</label>
                                        <input class='form-control' disabled="disabled" name='yf' data-type='text' />
                                    </div>

                                    <div class='col-md-6'>
                                        <label>保费</label>
                                        <input class='form-control' disabled="disabled" name='bf' data-type='text' />
                                    </div>
                                </div>

                                <div class='row'>
                                    <div class='col-md-6'>
                                        <label>运费返点</label>
                                        <input class='form-control' disabled="disabled" name='yffd' data-type='text' />
                                    </div>

                                    <div class='col-md-6'>
                                        <label>保费返点</label>
                                        <input class='form-control' disabled="disabled" name='bffd' data-type='text' />
                                    </div>
                                </div>

                                <div class='row'>

                                    <div class='col-md-6'>
                                        <label>提成</label>
                                        <input class='form-control' disabled="disabled" name='tc' data-type='text' />
                                    </div>

                                </div>

                                <div class="row">
                                    <div class='col-md-6'>
                                        <a class="btn btn-default" href="#" onclick="base_order_editFrm.ok();">保存</a>
                                        <a class="btn btn-danger" href="#" onclick="submit();">提交</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <input class='form-control' disabled="disabled" style="display:none;" name='iflag' data-type='text' />
    </div>
    <script>
        var base_order_edit;

        var base_order_editFrm = {
            ok: function () {
                //base_order_edit.refObj()
                //console.log(JSON.stringify(base_order_edit.refObj()));
                if (base_order_init.getObj_edit() == null) {
                    var obj = base_order_edit.refObj();
                    $.post('/api/base_order/add', obj, function () {
                        var msg = confirm('保存完毕，是否继续录入？');
                        if (!msg) {
                            window.location.reload();
                        }
                        //$.get('http://zymwx.nat123.net/api/sendMsg/sendSimpleMsg', {
                        //    touser: ($('select[name="company1"]').val() == '045e26fc-2998-4b52-b94f-4f3a2032bed4' || $('select[name="company2"]').val() == '045e26fc-2998-4b52-b94f-4f3a2032bed4') ? 'oMoxIxEMb-Xe6uc7cJpCP7Uw2zRA' : null,
                        //    url: null,
                        //    val0: "您有新的运单",
                        //    val1: "从" + $('select[name="barea"]').find('option:selected').text() + "\r\n到" + $('select[name="earea"]').find('option:selected').text(),
                        //    val2: "运费：" + $('input[name="yf"]').val() + "\r\n" + "货价：" + $('input[name="tolvalue"]').val()
                        //}, function (data) {
                        //    window.location.reload();
                        //});
                    });
                } else {
                    $.post('/api/base_order/edit', base_order_edit.refObj(), function () {
                        window.location.reload();
                    });
                }
            }
        }

        $(function () {
            base_order_edit = cusEdit();
            //disabled="disabled"
            if (base_order.data.account != "0") {
                $('select[name="company1"]').attr('disabled', 'disabled');
            }
            base_order_edit.init({
                data: base_order.data,
                editObj: (base_order_init.getObj_edit() == null && base_order.data.account != "0")
                    ? function () {
                        return { company1: base_order.data.account };
                    }() : base_order_init.getObj_edit()
            });
            base_order_edit.initEdit();
            $('.panel-collapse.collapse:gt(0)').removeClass('in');
            //if (base_order.data.company1.length == 1) {
            //    //$('select[name="company1"]').hide();
            //    $('select[name="company1"]').val(base_order.data.company1.id);
            //}
            $('#collapse2').on('show.bs.collapse', function () {
                if ($('select[name="barea"]').val() == null || $('select[name="earea"]').val() == null) {
                    $('#collapse0').collapse('show');
                    cus_IsNull('barea,earea');
                    return false;
                }
                $.get('/api/base_order/getcy', {
                    barea: $('select[name="barea"]').val(),
                    earea: $('select[name="earea"]').val()
                }, function (data) {
                    var val = $('select[name="company2"]').val();
                    var p = $('select[name="company2"]').parent();
                    $('select[name="company2"]').next().remove();
                    $('select[name="company2"]').remove();
                    p.append($('<select class="form-control" name="company2" data-type="select"></select>'));
                    $('#collapse2').addClass('in');
                    $('select[name="company2"]').select2({
                        allowClear: true,
                        placeholder: "Select a state",
                        data: data.data
                    });
                    $('select[name="company2"]').val(val).trigger('change');
                    $('#collapse2').removeClass('in');
                });
            });
        })

        function next(obj) {
            var idx = get_accordionIdx(obj);
            switch (idx) {
                case 0: {
                    if (cus_IsNull('barea,earea')) {
                        return;
                    }
                    $.get('/api/base_order/getcy', {
                        barea: $('select[name="barea"]').val(),
                        earea: $('select[name="earea"]').val()
                    }, function (data) {
                        var p = $('select[name="company2"]').parent();
                        $('select[name="company2"]').next().remove();
                        $('select[name="company2"]').remove();
                        p.append($('<select class="form-control" name="company2" data-type="select"></select>'));
                        $('#collapse2').addClass('in');
                        $('select[name="company2"]').select2({
                            allowClear: true,
                            placeholder: "Select a state",
                            data: data.data
                        });
                        $('#collapse2').removeClass('in');
                        cus_accordion(obj);
                    });
                    break;
                }
                case 1: {
                    if (cus_IsNull('thname,thphone,weight,volume,tolvalue')) {
                        return;
                    }
                    cus_accordion(obj);
                    break;
                }
                case 2: {
                    if (cus_IsNull('company1,company2')) {
                        return;
                    }
                    $.get('/api/base_order/getfy', {
                        barea: $('select[name="barea"]').val(),
                        earea: $('select[name="earea"]').val(),
                        companyid1: $('select[name="company1"]').val(),
                        companyid2: $('select[name="company2"]').val(),
                        weight: $('input[name="weight"]').val(),

                        volume: $('input[name="volume"]').val(),
                        tolvalue: $('input[name="tolvalue"]').val()
                    }, function (data) {
                        $('input[name="yf"]').val(data.yunfei_val);
                        $('input[name="bf"]').val(data.baofei_val);
                        $('input[name="yffd"]').val(data.yffd);
                        $('input[name="bffd"]').val(data.bffd);
                        $('input[name="tc"]').val(data.yftc);

                        cus_accordion(obj);
                    });
                    break;
                }
            }
        }

        function submit() {
            $('input[name="iflag"]').val('2');
            base_order_editFrm.ok();
        }
    </script>
</body>
</html>
